﻿var iMenuHeight;
var oHotMenu;
var oExpending = null;
var oShrinking = null;
var oHotPanel = null;
var Panels = 0;
function setHotMenu(o) {
    if (oHotMenu) oHotMenu.className = "menu";
    o.className = "hotmenu";
    oHotMenu = o;
    if (oExpending || oShrinking) oShrinking.className = "cpanel";
    else if (oHotPanel) oHotPanel.className = "cpanel";
}

function setHotPanel(o) {
    if (oExpending || oShrinking) return;
    var x = Math.floor(iMenuHeight / 2);

    if (oHotPanel == o) {
        o.className = "npanel";
        oShrinking = o;
        oHotPanel = null;
    }
    else {
        o.className = "hpanel";
        if (oHotPanel) {
            oHotPanel.className = "npanel";
            oShrinking = oHotPanel;
        }
        oHotPanel = o;
        oExpending = o;
    }
    expendPanel(x);
}

function expendPanel(x) {
    var m, h;
    if (oShrinking != null) {//合拢
        m = oShrinking.nextSibling;
        while (m.nodeName.toUpperCase() != "DIV") {
            m = m.nextSibling;
        }
        h = m.clientHeight;
        h = h - x;

        if (h <= 1) {
            m.style.height = "1px";
            m.style.display = "none";
            oShrinking = null;
        }
        else {
            m.style.height = h + "px";
        }
    }

    if (oExpending != null) {//展开
        m = oExpending.nextSibling;
        while (m.nodeName.toUpperCase() != "DIV") {
            m = m.nextSibling;
        }
        if (m.style.display == "none") {
            m.style.display = "block";
        }
        h = m.clientHeight;
        h = h + x - 1;

        if (h >= iMenuHeight) {
            m.style.height = iMenuHeight + "px";
            oExpending = null;
        }
        else {
            m.style.height = h + "px"; ;
        }
    }
    if (oShrinking == null && oExpending == null) return;
    if (x > 10) x = Math.floor(x / 2);
    setTimeout("expendPanel(" + x + ")", 50);
}

function addPanel(txt, href, icon) {
    var oc = 'setHotPanel(this);';
    if (href == null || href == '' || href == '#') {
        oc += 'return(false);';
        href = 'javascript:';
    }
    if (icon == null || icon == '') {
        icon = '/PanelBar/panel_defaul.gif';
    }
    Panels++;
    iMenuHeight -= 28;
    PanelBar.innerHTML += '<a class=npanel href="' + href + '" onclick="' + oc + '"><img class=panelicon src="' + icon + '" />' + txt + '</a>'
            + '<div class=menuouter style="display:none;"><div class=menuinner id=Panel_' + Panels + '></div></div>';
}
function addMenu(txt, href, icon, pid) {
    if (pid == null || pid == '') {
        pid = Panels;
    }
    if (icon == null || icon == '') {
        icon = '/GetIcon.ashx?f=' + href.split("?")[0];
    }
    document.getElementById("Panel_" + pid).innerHTML += '<a class="menu" href="' + href + '" onclick="setHotMenu(this);"><img class="menuicon" src="' + icon + '"  />' + txt + '</a>';
}